package com.greatwqs.wmall.order.provider.controller;

import lombok.extern.slf4j.Slf4j;
import springfox.documentation.annotations.ApiIgnore;

import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.greatwqs.wmall.common.module.model.LoginUser;
import com.greatwqs.wmall.common.module.util.JsonUtil;
import com.greatwqs.wmall.order.provider.model.dto.OrderCreateDto;
import com.greatwqs.wmall.order.provider.service.OrderService;

/**
 * @author wang-qingsong
 */
@Slf4j
@RestController
@RequestMapping(value = "/api/wmall/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping(value = "create")
    public Long createOrder(
            @ApiIgnore LoginUser loginUser,
            @RequestBody OrderCreateDto orderCreateDto) {
        orderCreateDto.setUserId(loginUser.getUserId());
        log.info("createOrder traceId：{}, orderCreateDto: {}", TraceContext.traceId(), JsonUtil.toJson(orderCreateDto));
        return orderService.createOrder(orderCreateDto);
    }
}